﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using BLL;

namespace MyVisionSystem
{
    public partial class Frm_Login : Form
    {
        public Frm_Login()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label5_Click(object sender, EventArgs e)
        {
            //验证用户输入的账号与密码格式是否正确
            if (this.textBox1.Text.Trim() == "")
            {
                MessageBox.Show("请输入账号","温馨提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
                return;
            }
            if (this.textBox2.Text.Trim() == "")
            {
                MessageBox.Show("请输入密码", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }
            //将用户输入的账号与密码封装成一个对象，传递给BLL层
            User user = new User()
            {
                Name = this.textBox1.Text.Trim(),
                PassWord = this.textBox2.Text.Trim()
            };
            //调用BLL层的方法，验证用户输入的账号与密码是否正确
            user = UserBLL.GetUserInfo(user);
            //判断是否查询到用户信息
            if (user == null)
            {
                //提示账号或密码错误
                MessageBox.Show("账号或密码错误", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            }
            else
            {
                Program.CurrentUser = user;//将当前用户信息保存到全局变量中
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
